package exception;

import jdk.nashorn.api.scripting.URLReader;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class FinallyDemo2 {
    public static void main(String[] args) throws IOException {
        FileOutputStream fos = null;
     try {//ctrl+alt+t 自动添加try-catch等异常处理
         fos = new FileOutputStream("fos.dat");
         fos.write(1);
     }catch (IOException e){
         System.out.println("出错并处理了");
     }finally {
         try {
             if(fos!=null){
                 fos.close();
             }
         }catch (IOException e){
             System.out.println("出错并处理了");
         }
     }
    }
}
